<?php

class BSMessage extends BSEntity {

    public $name = null;
    public $title;
    public $description;
    public $messageItems = array();
    protected $mediaManager = null;

    public function addMessageItem($itemData, $data = NULL) {

        if (is_array($itemData)) {
            //get media type
            $mediaTypeId = $itemData['media_type'];
            $mediaType = new BSMediaGroup($mediaTypeId);
            //create new message item
            $messageItem = new BSMedia();
            $messageItem->name = $itemData['name'];
            $messageItem->content = $itemData['media_content'];
            $messageItem->save();
            //add messageItem type
            $mediaType->addMember($messageItem);
            //add messageItem into message
            $messagMediaModel = new BSMMessageMedia();
            $messagMediaModel->message_id = $this->getId();
            $messagMediaModel->media_id = $messageItem->getId();
            $messagMediaModel->save();
        }
    }

    public function removeMessageItem($item) {
        
    }

    public function getMessageItem($itemContext = null, $data = NULL) {
        
    }

    public function getMessageItems($itemContext = NULL, $data = NULL) {
        
    }

    /**
     * 
     * @param type $data
     * @return BSMediaManager
     */
    public function getMediaManager($data = NULL){
        if($this->mediaManager == NULL){
            $this->mediaManager = new BSMediaManager($this);            
        }
        return $this->mediaManager;
    }
}

?>
